// 为红人区域绑定点击切换事件
var starsUl = document.querySelector('.stars')
var stars = starsUl.querySelectorAll('li')
for (let i = 0; i < stars.length; i++) {
  stars[i].className = "unselected"
}
stars[0].className = "selected"
for (let i = 0; i < stars.length; i++) {
  stars[i].onclick = function () {
    for (let i = 0; i < stars.length; i++) {
      stars[i].className = "unselected"
    }
    this.className = "selected"
  }
}

// 为红人区域视频介绍绑定点击播放/暂停事件
var starWallVideo = document.querySelector('.starWallVideo')
var videoMask = starWallVideo.querySelector('.videoMask')
var playVideo = false
starWallVideo.onclick = function () {
  playVideo = !playVideo
  if (playVideo) {
    console.log('播放')
    videoMask.style.visibility = 'hidden'
  } else {
    console.log('暂停')
    videoMask.style.visibility = 'visible'
  }
}

// 抽奖区域轮盘点击事件
// 获取轮盘转动时需要显示的数据数组
var lotterying = document.querySelectorAll('.lotterying li')
// 获取绑定事件的按钮
var lotteryLast = document.querySelectorAll('.lottery li')[8]
var lotteryBtn = lotteryLast.querySelector('img')
// 当前被选中的项的索引
var i = 0;
// 刷新按钮
var refreshBtn = document.querySelectorAll('.starWallLotteryBottom span')[1]
// 中奖记录按钮
var recordBtn = document.querySelectorAll('.starWallLotteryBottom span')[0]

lotteryBtn.onclick = function () {
  // 按钮禁用点击事件
  refreshBtn.classList.add("notclick");
  recordBtn.classList.add("notclick");
  lotterying[lotterying.length - 1].style.visibility = "visible"
  timer1 = setInterval(function () {
    lotterying[i].style.visibility = "visible"
  }, 0)
  timer2 = setInterval(function () {
    lotterying[i].style.visibility = "hidden"
    // 随机生成0~7之间且不等于i的整数
    i = judge(i)
    console.log(i)
  }, 100)
  setTimeout(function () {
    clearInterval(timer1);
    clearInterval(timer2);
    lotterying[i].style.visibility = "visible"
    refreshBtn.classList.remove("notclick");
    recordBtn.classList.remove("notclick");
  }, 2500)
}

// 给刷新按钮绑定刷新事件
refreshBtn.onclick = function () {
  lotterying[lotterying.length - 1].style.visibility = "hidden"
  lotterying[i].style.visibility = "hidden"
}


// 连续生成0~7之间的随机整数，相邻两数不相等
function judge (bejin) {
  var n = Math.floor(Math.random() * (7 + 1))
  if (bejin === n) {
    n = judge(n)
  }
  return n
}

// var num = 0
// for (var i = 0; i < 20; i++) {
//   num = judge(num)
//   console.log(num)
// }

// 随机生成0~7之间的整数
// Math.floor(Math.random() * (7 + 1))